package org.swingDemo.util;

import javax.swing.*;
import java.awt.event.ActionListener;

public class UIUtil {

    public static JLabel createLabel(String text) {
        JLabel label = new JLabel(text);
        label.setHorizontalAlignment(SwingConstants.CENTER);
        return label;
    }

    public static JLabel createIconLabel(Icon icon) {
        JLabel label = new JLabel();
        label.setIcon(icon);
        label.setVerticalAlignment(SwingConstants.CENTER);
        label.setHorizontalAlignment(SwingConstants.CENTER);
        return label;
    }

    public static JButton createButton(String text, Icon icon, ActionListener listener) {
        JButton button = new JButton(text, icon);
        button.addActionListener(listener);
        return button;
    }

    public static JRadioButton createRadioButton(String text, ButtonGroup buttonGroup) {
        JRadioButton radioButton = new JRadioButton(text);
        radioButton.setSelected(false);
        buttonGroup.add(radioButton);
        return radioButton;
    }

    public static JTextField createTextField(String text, boolean enabled) {
        JTextField textField = new JTextField(text);
        textField.setEnabled(enabled);
        return textField;
    }

}
